package top.wbhzx.pojo;

import java.lang.reflect.Field;
import java.util.Map;

public class AttrUtil {

	public static void setAttribute(Object o,String field, Object keyWord) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
	        Field f = o.getClass().getDeclaredField(field); 
	        f.setAccessible(true);
	        if(f.getName().equals("registerTime")) {
	        	f.set(o, (Long)keyWord); 
	        	System.out.println("-------------"+f.getName());
	        }else {
	        	
	        	f.set(o, keyWord); 
	        }
	}
	
	public static String getAttribute(Object o,String field) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
	    String r = "";
	        Field f = o.getClass().getDeclaredField(field); 
	        f.setAccessible(true); 
	        r =  f.get(o).toString();
	    return r;
	}
	
	public static void setAttributes(Object o, Map<String, Object> map) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
		for(String key : map.keySet()) {
			AttrUtil.setAttribute(o, key, map.get(key));
			
		}
	}
	
}
